#include <iostream>
#include <unordered_map>
#include <cmath>

bool is_prime(int num) {
    if (num < 2) {
        return false;
    }
    for (int i = 2; i <= sqrt(num); i++) {
        if (num % i == 0) {
            return false;
        }
    }
    return true;
}

int closest_prime(int num) {
    if (is_prime(num)) {
        return num;
    }

    int lower = num - 1;
    int upper = num + 1;

    while (true) {
        if (is_prime(lower)) {
            return lower;
        } else if (is_prime(upper)) {
            return upper;
        } else {
            lower--;
            upper++;
        }
    }
}

int word_to_number(const std::string& word) {
    std::unordered_map<std::string, int> numbers = {
        {"zero", 0}, {"one", 1}, {"two", 2}, {"three", 3}, {"four", 4},
        {"five", 5}, {"six", 6}, {"seven", 7}, {"eight", 8}, {"nine", 9}
    };
    return numbers[word];
}

int main() {
    std::string word1, word2, word3;
    std::cin >> word1 >> word2 >> word3;

    try {
        int number = word_to_number(word1) * 100 + word_to_number(word2) * 10 + word_to_number(word3);
        if (number >= 100 && number <= 999) {
            std::cout << closest_prime(number) << std::endl;
        } else {
            std::cout << "Wrong input" << std::endl;
        }
    } catch (...) {
        std::cout << "Wrong input" << std::endl;
    }

    return 0;
}
